<template>
	<view>
		<u-cell-group>
			<u-cell-item  @click="chooseAvatar"  title="头像">
				<u-avatar slot="right-icon" :src="user.avatarUrl"></u-avatar>
			</u-cell-item>
		</u-cell-group>
		<br/>
		<u-cell-group>
			<u-cell-item   title="名称" :value="user.name"></u-cell-item>
			<u-cell-item   title="邮箱" :value="user.email"></u-cell-item>
			<u-cell-item   title="手机号" :value="user.telephone"></u-cell-item>
		</u-cell-group>
		<drag-button :isDock="true" ></drag-button>
	</view>
</template>

<script>
	import dragButton from '../../components/drag-button/drag-button.vue'
	export default{
		components:{
			dragButton
		},
		data(){
			return{
				
			}
		},
		computed:{
			user(){
				return this.$store.state.user
			}
		},
		methods:{
			chooseAvatar() {
				this.$u.route({
					url: '/uview-ui/components/u-avatar-cropper/u-avatar-cropper',
					params: {
						destWidth: 300,
						rectWidth: 200,
						fileType: 'jpg',
					}
				})
			},
		},
		created() {
			uni.$on('uAvatarCropper', path => {
				this.avatar = path;
				uni.uploadFile({
					url: '/api/backstage/announcement/uploadImage',
					filePath: path,
					name: 'file',
					complete: (res) => {
						this.user.avatarUrl = (JSON.parse(res.data)).data[0]
					}
				});
			})
		}
	}
</script>

<style>
	page{
			 background-color: #f7f7f7;;
		 }
</style>
